package com.bnz.run.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.bnz.run.properties.JdbcProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
//相当于以前的applicationContext.xml的配置文件
//@PropertySource("classpath:/properties/db.properties")
public class MyConfig {
    //配置数据源
    @Value("${jdbc.driverClassName}")
    private String driverClassName;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;
//    @Bean
//    public DruidDataSource druidDataSource(){
//        DruidDataSource druidDataSource = new DruidDataSource();
//        //set赋值
//        druidDataSource.setDriverClassName(driverClassName);
//        druidDataSource.setUrl(url);
//        druidDataSource.setUsername(username);
//        druidDataSource.setPassword(password);
//        return druidDataSource;
//    }

    @Bean
    public DruidDataSource druidDataSource01(JdbcProperties jdbc){
        DruidDataSource dataSource = new DruidDataSource();
        //set赋值
        dataSource.setDriverClassName(jdbc.getDriverClassName());
        dataSource.setUrl(jdbc.getUrl());
        dataSource.setUsername(jdbc.getUsername());
        dataSource.setPassword(jdbc.getPassword());
        return dataSource;

    }
}
